import axios from 'axios';

import { Loading, Message } from 'element-ui';

const BASE_URL_1 = 'http://timemeetyou.com:8889/api/private/v1/'
const BASE_URL_2 = 'https://www.liulongbin.top:8888/api/private/v1/'
const BASE_URL_3 = 'http://www.ysqorz.top:8888/api/private/v1/'
const BASE_URL_4 = 'http://119.23.48.121:8888/api/private/v1/'
const BASE_URL_5 = 'http://127.0.0.1:8888/api/private/v1/'

export function request1(config) {
  const instance = axios.create({
    baseURL: BASE_URL_5,
    timeout: 5000
  });
  let loadingInstance = null;
  instance.interceptors.request.use(config => {
    config.headers.Authorization = window.sessionStorage.getItem('token');
    loadingInstance = Loading.service({
      text: '正在全力加载中...',
      spinner: "el-icon-loading",
      background:"rgba(0, 0, 0, 0.8)"
    });
    return config
  })
  instance.interceptors.response.use(res => {
    loadingInstance.close();
    return res.data;
  }, err => {
    loadingInstance.close();
    Message.error(new Error('获取数据失败，请稍后再试'))
    return err
  })

  return instance(config)
}
export function request2(config) {
  const instance = axios.create({
    baseURL: BASE_URL_2,
    timeout: 5000
  });
  let loadingInstance = null;
  instance.interceptors.request.use(config => {
    config.headers.Authorization = window.sessionStorage.getItem('token2');
    loadingInstance = Loading.service({
      text: '正在全力加载中...',
      spinner: "el-icon-loading",
      background:"rgba(0, 0, 0, 0.8)"
    });
    return config
  })
  instance.interceptors.response.use(res => {
    loadingInstance.close();
    return res.data;
  }, err => {
    loadingInstance.close();
    Message.error(new Error('获取数据失败，请稍后再试'))
    return err
  })

  return instance(config)
}